// this half of the program is for array based operations that were to b done...
#include<stdio.h>
#include<stdlib.h>

struct node
{
int val;
struct node *next;
};

struct node *insert(struct node *list,int n)
{
struct node *temp;
temp=malloc(sizeof(struct node));
temp->val=n;
temp->next = list;
return temp;
}

void print(struct node *list)
{
while (list!=NULL)
{
printf("values are:%d \n",list->val);
list=list->next;
}
}
//1.reverse a linked list
struct node *reverse(struct node *list)
{
	struct node *temp, *t,*t2;
	t=malloc(sizeof(struct node));
	t->val=list->val;
	t->next=NULL;
	list=list->next;
	temp=malloc(sizeof(struct node));
	temp->val=list->val;
	temp->next=t;
	while((list->next)!=NULL)
	{
		t2=malloc(sizeof(struct node));
		list=list->next;
		t2->val=list->val;
		t2->next=temp;
		temp=t2;
	}
	return temp;
}
//2.to append an element
struct node *append(struct node *list,int n)
{
struct node *a;

while(a->next!=NULL)
{
list=list->next;
if(list->next==NULL)
	{
	a=malloc(sizeof(struct node));
	a->val=n;
	list->next=a;
	a->next=NULL;	
	}
}
return a;
}
//3.deletion of an element from a link list depending on it's index
struct node *pop(struct node list,int x)
{
struct node *prev,*cur;
while(list->next!=NULL)
{
prev=malloc(sizeof(struct node));
prev->val=list->val;
prev->next=list->next;

}
}
void main()
{
int x,i,tnum,z;
struct node *a=NULL;
printf("lenght of link list:");
scanf("%d",&x);
for (i=0;i<x;i++)
{
printf("enter the value:");
scanf("%d",&tnum);
a=insert(a,tnum);
} 

printf("\nMenu\n1.reverse\n2.append\n3.deletion\nselect an operation that u would like to perform on the given link list created:");
scanf("%d",&z);
switch(z)
{
case 1: reverse(a);
	break;
case 2: printf("enter the value that you want to append:");
	scanf("%d",&x);
	append(a,x);
	break;
case 3: printf("enter the index element that u want to delete:");
	scanf("%d",&x);
	pop(a,x);
	break;
default:printf("you entered a wrong option\n");
	break;
}
printf("the values currently stored in the linked list are(in right order are):\n");
print (a);
}


//this half of the program is for the linked list based operations
#include<stdio.h>
#include<stdlib.h>

struct node
{
int val;
struct node *next;
};

struct node *insert(struct node *list,int n)
{
struct node *temp;
temp=malloc(sizeof(struct node));
temp->val=n;
temp->next = list;
return temp;
}

void print(struct node *list)
{
while (list!=NULL)
{
printf("values are:%d \n",list->val);
list=list->next;
}
}
//1.reverse a linked list
struct node *reverse(struct node *list)
{
	struct node *temp, *t,*t2;
	t=malloc(sizeof(struct node));
	t->val=list->val;
	t->next=NULL;
	list=list->next;
	temp=malloc(sizeof(struct node));
	temp->val=list->val;
	temp->next=t;
	while((list->next)!=NULL)
	{
		t2=malloc(sizeof(struct node));
		list=list->next;
		t2->val=list->val;
		t2->next=temp;
		temp=t2;
	}
	return temp;
}
//2.to append an element
struct node *append(struct node *list,int n)
{
struct node *a;

while(a->next!=NULL)
{
list=list->next;
if(list->next==NULL)
	{
	a=malloc(sizeof(struct node));
	a->val=n;
	list->next=a;
	a->next=NULL;	
	}
}
return a;
}
//3.deletion of an element from a link list depending on it's index
struct node *pop(struct node list,int x)
{
struct node *prev,*cur;
while(list->next!=NULL)
{
prev=malloc(sizeof(struct node));
prev->val=list->val;
prev->next=list->next;

}
}
void main()
{
int x,i,tnum,z;
struct node *a=NULL;
printf("lenght of link list:");
scanf("%d",&x);
for (i=0;i<x;i++)
{
printf("enter the value:");
scanf("%d",&tnum);
a=insert(a,tnum);
} 

printf("\nMenu\n1.reverse\n2.append\n3.deletion\nselect an operation that u would like to perform on the given link list created:");
scanf("%d",&z);
switch(z)
{
case 1: reverse(a);
	break;
case 2: printf("enter the value that you want to append:");
	scanf("%d",&x);
	append(a,x);
	break;
case 3: printf("enter the index element that u want to delete:");
	scanf("%d",&x);
	pop(a,x);
	break;
default:printf("you entered a wrong option\n");
	break;
}
printf("the values currently stored in the linked list are(in right order are):\n");
print (a);
}
